package com.lut.teacher.teacherservice.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lut.teacher.teacherservice.entity.vo.DatalistVo;
import com.lut.teacher.teacherservice.utils.PageUtils;
import com.lut.teacher.teacherservice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lut.teacher.teacherservice.entity.TeacherProjectEntity;
import com.lut.teacher.teacherservice.service.TeacherProjectService;




/**
 * 
 *
 * @author tongyerui
 * @email tongyerui@gmail.com
 * @date 2021-07-06 11:31:08
 */
@RestController
@RequestMapping("teacherservice/teacherproject")
public class TeacherProjectController {
    @Autowired
    private TeacherProjectService teacherProjectService;
    @RequestMapping("/teacher/list")
    // @RequiresPermissions("teacherservice:teacherproject:list")
    public R listinfo(@RequestParam Map<String, Object> params){
        PageUtils page = teacherProjectService.queryProject(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
   // @RequiresPermissions("teacherservice:teacherproject:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teacherProjectService.queryPage(params);

        return R.ok().put("page", page);
    }
    //
    @RequestMapping("/data/list")
    // @RequiresPermissions("teacherservice:teacherproject:list")
    public R listdata(@RequestParam Map<String, Object> params){
        List<Map<String, Object>> maps = teacherProjectService.queryProjectDta();
        List<DatalistVo> datalist=new ArrayList<>();
        for(int i=0;i<maps.size();i++){
            DatalistVo datalistVo = new DatalistVo();
            datalistVo.setName((String) maps.get(i).get("projectName"));
            datalistVo.setValue(Integer.parseInt(maps.get(i).get("total").toString()));
            datalist.add(datalistVo);

        }


        return R.ok().put("datalist",datalist);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{projectId}")
    //@RequiresPermissions("teacherservice:teacherproject:info")
    public R info(@PathVariable("projectId") String projectId){
		TeacherProjectEntity teacherProject = teacherProjectService.getById(projectId);

        return R.ok().put("teacherProject", teacherProject);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("teacherservice:teacherproject:save")
    public R save(@RequestBody TeacherProjectEntity teacherProject){
		teacherProjectService.save(teacherProject);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("teacherservice:teacherproject:update")
    public R update(@RequestBody TeacherProjectEntity teacherProject){
		teacherProjectService.updateById(teacherProject);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("teacherservice:teacherproject:delete")
    public R delete(@RequestBody String[] projectIds){
		teacherProjectService.removeByIds(Arrays.asList(projectIds));

        return R.ok();
    }

}
